<?php


$feed_url = "http://www.health.com/health/diet-fitness/feed";

require ('mysqli_connect.php'); // Connect to the db.

function debug_to_console ($data)
{
    if (is_array($data))
        $output = "<script>console.log( 'Debug Objects: " . implode(',', $data) .
                 "' );</script>";
    else
        $output = "<script>console.log( 'Debug Objects: " . $data .
                 "' );</script>";
    
    echo $output;
}


// for adding the Categories
function list_categories ()
{

			echo '<li class="odd"><a href="rssfeed_exec.php?run=1"</a>Diet & Fitness</li>';
			echo '<li class="odd"><a href="rssfeed_exec.php?run=2"</a>Food & Recipes</li>';
			echo '<li class="odd"><a href="rssfeed_exec.php?run=3"</a>Cholesterol</li>';
			echo '<li class="odd"><a href="rssfeed_exec.php?run=4"</a>Appetizers Recipes</li>';
			echo '<li class="odd"><a href="rssfeed_exec.php?run=5"</a>Asian Recipes</li>';
			echo '<li class="odd"><a href="rssfeed_exec.php?run=6"</a>Egg Recipes</li>';
			echo '<li class="odd"><a href="rssfeed_exec.php?run=7"</a>Potato Recipes</li>';
			echo '<li class="odd"><a href="rssfeed_exec.php?run=8"</a>Barbecue & Grilling Recipes</li>';
			echo '<li class="odd"><a href="rssfeed_exec.php?run=9"</a>Chocolate Recipes</li>';
			echo '<li class="odd"><a href="rssfeed_exec.php?run=10"</a>Christmas Recipes</li>';
			echo '<li class="odd"><a href="rssfeed_exec.php?run=11"</a>Cocktail & Mixed Drink Recipes</li>';
			echo '<li class="odd"><a href="rssfeed_exec.php?run=12"</a>No Cook Recipes</li>';
			echo '<li class="odd"><a href="rssfeed_exec.php?run=13"</a>Thanksgiving Recipes</li>';
			echo '<li class="odd"><a href="rssfeed_exec.php?run=14"</a>Copycat & Restaurant Recipes</li>';
			echo '<li class="odd"><a href="rssfeed_exec.php?run=15"</a>One-Dish Recipes</li>';
			echo '<li class="odd"><a href="rssfeed_exec.php?run=16"</a>Lactose Recipes</li>';
			echo '<li class="odd"><a href="rssfeed_exec.php?run=17"</a>Pasta Recipes</li>';
			echo '<li class="odd"><a href="rssfeed_exec.php?run=18"</a>Turkey Recipes</li>';
			echo '<li class="odd"><a href="rssfeed_exec.php?run=19"</a>Dessert Recipes</li>';
			echo '<li class="odd"><a href="rssfeed_exec.php?run=20"</a>Pizza Recipes</li>';
			echo '<li class="odd"><a href="rssfeed_exec.php?run=21"</a>Valentines Day Recipes</li>';
			echo '<li class="odd"><a href="rssfeed_exec.php?run=22"</a>Dinner Party Recipes</li>';
			echo '<li class="odd"><a href="rssfeed_exec.php?run=23"</a>Pork Chop Recipes</li>';
			echo '<li class="odd"><a href="rssfeed_exec.php?run=24"</a>Vegetarian & Vegan Recipes</li>';
				
			
} // End of the function list_categories.

function list_feeds ()
{
	if( isset($_SESSION['FEED_URL']) ) 
	{
		$feed_url=$_SESSION['FEED_URL'];
	}
	
	$rss = simplexml_load_file($feed_url);
	
	echo '<div class"rssDiv">';
	echo '<div class="rssFeedTitle">'. $rss->channel->title . '</div>';

	foreach ($rss->channel->item as $item) {
		echo '<div class="rssFeedItem"><a href="'. $item->link .'">' . $item->title . "</a></div>";
		echo '<div class="rssFeedDate">' . $item->pubDate . "</div>";
	}
	echo '</div>';
	
}
?>


<?php
function list_feedsinTable ()
{
	if( isset($_SESSION['FEED_URL']) ) 
	{
		$feed_url=$_SESSION['FEED_URL'];
	}
	
	$rss = simplexml_load_file($feed_url);
	echo '<div class="rssFeedTitle">'. $rss->channel->title . '</div>';
	
	echo '<table id="rss_table" summary="RSS FEEDS">
    <thead>
    	<tr>
        	<th scope="col">Feeds</th>
            <th scope="col">TimeStamp</th>
   		</tr>
    </thead><tbody>
    	';
	foreach ($rss->channel->item as $item) {
		echo '<tr><td><a class="feed_links" href="'. $item->link .'">' . $item->title . "</a></td>";
		echo '<td>' . $item->pubDate . "</td></tr>";
	}
	echo '</tbody></table>';
	
}
?>
    

<?php
include('header.php');
?>
    
    
    		<div class="left_content">
			<div class="title_box">Categories</div>
			<ul class="left_menu">
                <?php list_categories();?>
            </ul>
            
             <div class="title_box">Newsletter</div>  
		     <div class="border_box">
				<input type="text" name="newsletter" class="newsletter_input" value="your email"/>
		        <a href="#" class="join">join</a>
		     </div> 
            
            
            <div class="banner_adds">
     			<a id="left_banner" href="#"><img src="../images/mcd_banner.jpg" alt="" title="" border="0" /></a>
     		</div>   
     		
		</div>

		</div>

		<div class="center_content">
		    <?php list_feedsinTable($feed_url);?>
		            	

        </div>
		<!-- end of center content -->

		
<?php
include('footer.php');
?>